/**
 * Created by liuqingxia on 2016/6/30.
 */


//提示语
var paramsCommentMap = {
    ygIp: "请输入机器IP",
    ygLocation: "请输入机器目录"
}

/**
 * main入口
 */
$(document).ready(function () {
    clickInsertBtn();
});

/**
 * 点击"提交"按钮
 */
function clickInsertBtn() {

    $(document).on("click", "#commitBtn", function () {
        var params = getFormParams("machine-insert-form");
        // console.log("params:" + JSON.stringify(params));
        if (!validateParams(params)) {
        	
        } else {
        	params['projectName'] = $("#projectSelected").val();
            sendParams(params);
        }
    });
}

/**
 * 向后台发送请求数据
 * @param params
 */
function sendParams(params) {
    $.postHttpSync(params, getUrlBySuffix("/yugong/machine/insert"), function (json) {
        // console.log(JSON.stringify(json));
        if (json && json.success) {
            swal("提示", json['message'], "success");
        } else {
            swal("提示", json["message"], "error");
        }
    });
}

/**
 * 检验用户输入参数
 * @param params
 * @returns {boolean}
 */
function validateParams(params) {
    for (var propName in params) {
        var propValue = params[propName];
        if (isNull(propValue)) {
            var comment = paramsCommentMap[propName];
            if (comment != "undefined") {
                swal("提示", comment, "error");
                return false;
            }
        }
    }
    return true;
}
    
    